//
//  ViewController.m
//  NSURL
//
//  Created by dllo on 16/8/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//NSURL负责请求的地址
 NSURL *baiduURL = [NSURL URLWithString:@"https://www.baidu.com/html?userName=xxx&pwdxxx"];
//    NSLog(@"baiduURL : %@",baiduURL);
//    完整的URL对应的字符串
    NSLog(@"%@",[baiduURL absoluteString]);
//    主机地址或域名
    NSLog(@"%@",baiduURL.host);
//    NSLog(@"%@",baiduURL.port);
//    主机地址/域名后对应的路径
    NSLog(@"%@",baiduURL.path);
//    NSLog(@"%@",baiduURL.fragment);
//    NSLog(@"%@",baiduURL.user);
//    NSLog(@"%@",baiduURL.parameterString);
//    ？以后的问题
    NSLog(@"%@",baiduURL.query);
//    遵循的协议
    NSLog(@"%@",baiduURL.scheme);
//    除了协议之外的部分
    NSLog(@"%@",baiduURL.resourceSpecifier);
    
    
//可变请求和不可变请求
//1.NSURLRequest
//    不可变啥都不能改
NSURLRequest *baiduRequest = [NSURLRequest requestWithURL:baiduURL];
//    2.NSMutableURLRequest
//    一般处理网络请求，都是用NSMutableURLRequest
NSMutableURLRequest *baiduMutableRequest = [NSMutableURLRequest requestWithURL:baiduURL];
//  1超时时间，一个请求持续多久，会失败
    baiduMutableRequest.timeoutInterval = 60;
//   2 HTTPMethod请求的姿势 GET POST PUT DELETE
    baiduMutableRequest.HTTPMethod = @"GET";
//    3allHTTPHeaderFields 设置网络请求
    baiduMutableRequest.allHTTPHeaderFields = @{@"User-Agent":@"iOS 10.0 / iphone8,0"};

    //    根据字典特性，key相同情况下，后填入的值，会覆盖前面的值
//    [baiduMutableRequest setValue:@"iOS 10.0 / iphone8,2" forHTTPHeaderField:@"User-Agent"];
//    NSLog(@"%@",baiduMutableRequest.allHTTPHeaderFields);
    
    [baiduMutableRequest valueForHTTPHeaderField:@"User-Agent"];
//NSLog(@"%@",baiduMutableRequest.allHTTPHeaderFields);
    baiduMutableRequest.HTTPBody = [NSData data];
//    baiduMutableRequest 
//    3NSURLResponse响应
//    NSURLResponse *
    NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:baiduURL statusCode:200 HTTPVersion:@"HTTP/1.1" headerFields:@{@"date":[NSData data]}];
//    statusCode状态码
//    response.statusCode
//    allHeaderFields响应头
//    内容类型 编码
//    Content-Type : application/json;charset:utf-8
//    时间 日期
//    缓存一些内容
    NSLog(@"%ld",[response statusCode]);
    NSLog(@"%@",[response allHeaderFields]);
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
